package com.dianjing.dianqun.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
 * 线程池 方法类
 * @author djn104
 *
 */
public class ExecutorUtils {
	private static ExecutorUtils instance = new ExecutorUtils();

	private static final int corePoolSize = 20;
	private static final int maximumPoolSize = 100;
	private static BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(maximumPoolSize);

	private static ThreadFactory factory = new ThreadFactory() {
		@Override
		public Thread newThread(Runnable r) {
			return new Thread(r);
		}
	};

	private static ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, 24,
			TimeUnit.HOURS, workQueue, factory);

	public static synchronized ExecutorUtils sharedInstance() {
		synchronized (ExecutorUtils.class) {
			if (instance == null) {
				instance = new ExecutorUtils();
			}
			return instance;
		}
	}

	public void doRun(Runnable task) {
		executor.execute(task);
	}

	public ThreadPoolExecutor getExecutor() {
		return executor;
	}
}
